#!/usr/bin/env python
# -*- coding: utf-8 -*-

# You may use this module instead of paster
# and thus use the CherryPy 3 WSGI server
# This won't affect the rest of your code

if __name__ == '__main__':
    from optparse import OptionParser
    from paste.deploy import loadapp
    from cherrypy.wsgiserver import CherryPyWSGIServer

    parser = OptionParser("usage: %prog -c config.ini")
    parser.add_option("-c", "--config", dest="config",
                      help="absolute path to the config file")
    
    (options, args) = parser.parse_args()

    if not options.config:
        parser.print_help()
        sys.exit(2)

    # If I could understand paste.server_factory I would use it...
    app = loadapp('config:%s' % options.config)
    server = CherryPyWSGIServer(('localhost', 8080), [('', app)],
                                server_name='localhost')

    try:
        print "Serving HTTP on http://localhost:8080"
        server.start()
    except KeyboardInterrupt:
        server.stop()

        
